const cloud = getApp().cloud;
const app = getApp();
Page({
  data: {
    sf:false,
  },

  //分享
  share(){

    cloud.function.invoke('client',{},'createShareLog').then(res => {
      console.log('share---邀请好友参与活动',res,res.data.shareLogId);  
      this.setData({
        shareLogId:res.data.shareLogId
      })

      my.showSharePanel();
      
    }) 

  },

  //查看投票排行榜
  lookList(){
    my.navigateTo({ url: '../vote/vote' })
  },

  //挑战产品原创设计
  gosheji(){
    my.navigateTo({ url: '../createPS/createPS' })
  },

  //去抽奖
  goLottery(){
    my.navigateTo({ url: '../lottery/lottery' })
  },

  //返回首页
  goIndex(){

    //关闭所有页回到第一页
    my.reLaunch({
      url: '../index/index'
    })

  },

  //获取用户信息
  getUserInfo(){

    cloud.function.invoke('client',{},'getUserInfo').then(res => {
      console.log('share---获取用户信息',res);  
      this.setData({
        drawNum:res.data.drawNum
      })
    }) 

  },



  onLoad(query) {


    //获取kv里面的图片
    //
    if(query.defaultImg){
      this.setData({
        kv:query.defaultImg
      })
    }

    //获取用户信息
    this.getUserInfo();


    let i = 0;

    if(i==0){

      this.setData({
        sf:true,
      })

      setTimeout(()=>{

        this.setData({
          sf:false
        })

      },2000)

    }

    if(query.bs){
      
    }
    
  },


  //分享途径
  //口味和文案的标题需要体现在拖拽完成图上

  onShareAppMessage() {

    return {
      title: '真果粒新品研究院',
      desc: '小程序官方示例 Demo，展示已支持的接口能力及组件。',
      path: `pages/index/index?shareLogId=${this.data.shareLogId}`,
      imageUrl:this.data.defaultImg
    };

  }

});
